package com.qd.panda.stroke;

import com.cdqidi.dto.ApiResult;
import com.cdqidi.dto.ApiResultWrapper;
import com.cdqidi.repeat.annotation.RepeatSubmit;
import com.qd.common.sys.annotation.OperatorInfo;
import com.qd.common.sys.enums.OperatorType;
import com.qd.panda.service.refund.RefundService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * WEB_加油站
 *
 * @author sjk
 */
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/sys/gasStation/")
@Slf4j
public class GasStationController {

    private final RefundService refundService;

    /**
     * 申请退款
     *
     * @param map 订单ID
     * @return true or false
     */
    @RepeatSubmit
    @PreAuthorize("@ps.hasPermission('system:userStrokeOrder:refundRequests')")
    @OperatorInfo(title = "退款申请", operator = OperatorType.OTHER)
    @PostMapping("/refundRequests")
    public ApiResultWrapper<Object> refundRequests(@Validated @RequestBody Map<String, String> map) {
        String orderId = map.get("orderId");
        if (!StringUtils.hasLength(orderId)) {
            return ApiResult.error("订单ID不能为空");
        }
        refundService.refundRequests(orderId);
        return ApiResult.success();
    }
}